<?php
/**
 * 
 * @author tangbl
 * 
 */
class ModuleAction extends CommonAction {
	
	public function _initialize() {
		parent::_initialize();
		parent::_initmenu();	
	}
	
	/**
	 * 列表
	 */
	public function index() {
		
		if(IS_AJAX){
			import('ORG.Util.Page');
			$Module  = D("Module");
			
			$orderDesc = $this->_get("orderDirection","trim","desc");
			$orderName = $this->_get("orderName","trim","addtime");
			$pageNum   = $this->_get("pageNum","intval",C('web_admin_pagenum'));
			$nowPage   = $this->_get("p","intval",1);
			
			$map       = unescape($this->_get("where"));
			$map       = "1=1 ".$map;
			$count     = $Module->where($map)->count();
			$Page      = new Page($count);
			$show      = $Page->show();
			$list      = $Module->where($map)->order($orderName.' '.$orderDesc)
						 ->page($nowPage.','.$pageNum)->select();
			$totalPage = ceil($count/$pageNum);
			C('web_admin_pagenum',$pageNum);
			
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'rows'=>array(),'totalPage'=>$totalPage);
			$lang    = getLang();
			foreach($list AS $row){
				if(array_key_exists($row['lang'],C('LANG_ARRAY'))){
					$_lang = $row['lang'];
				}else{
					$_lang = L('cfg_form_tis_select_nolang');
				}
					
				//父模型名称
				if($row['module_pid']){
					$pModule = M('Module');
					$pData  = $pModule->find($row['module_pid']);
					$module_pid = $pData['module_name'];
				}else{
					$module_pid = L('mod_inherit_form_ele_nopid');
				}

				//处理字符串
				$deal = '';
				//字段类别管理
				if($row['module_type']==1 || $row['module_type']==2){
					$deal .= '<a href="'.__URL__.'/tablist/id/'.$row['id'].'" class="btn blue icn-only" title="'.L('mod_list_deal_tab').'"><i class="icon-list"></i></a>';
				}
				//字段管理
				$deal .= '<a href="'.__URL__.'/filedlist/id/'.$row['id'].'" class="btn green icn-only" title="'.L('mod_list_deal_filed').'"><i class=" icon-columns"></i></a>';
				//修改模型
				$deal .= '<a href="'.__URL__.'/edit/id/'.$row['id'].'" class="btn purple icn-only" title="'.L('cfg_list_itf_btn_modify').'" data-id="'.$row['id'].'"><i class="icon-edit"></i></a>';
				//列表设置
				if($row['module_type']==1 || $row['module_type']==2){
					$deal .= '<a href="'.__URL__.'/listedit/id/'.$row['id'].'" class="btn yellow icn-only" title="'.L('mod_list_btn_listset').'" data-id="'.$row['id'].'"><i class="icon-cog"></i></a>';
				}
				//主模型扩展
				if($row['module_type']==1){
					$deal .= '<a href="'.__URL__.'/inherit/id/'.$row['id'].'" class="btn icn-only" title="'.L('mod_listedit_form_btn_copy').'" data-id="'.$row['id'].'"><i class="icon-copy"></i></a>';
				}
				
				//查看模型
				if($row['module_type']==1 || $row['module_type']==2){
					if($row['module_pid']){
						$deal .= '<a href="'.__APP__.'/'.ucfirst($module_pid).'/index/module_id/'.$row['id'].'" class="btn black icn-only" title="'.L('mod_listedit_form_btn_see').'"><i class="icon-hand-right"></i></a>';
					}else{
						$deal .= '<a href="'.__APP__.'/'.ucfirst($row['module_name']).'/index/module_id/'.$row['id'].'" class="btn black icn-only" title="'.L('mod_listedit_form_btn_see').'"><i class="icon-hand-right"></i></a>';
					}
				}
				
				//删除模型
				$deal .= '<a class="btn red icn-only delAlone" title="'.L('cfg_list_itf_btn_delete').'" data-id="'.$row['id'].'"><i class="icon-remove"></i></a>';
					
				$entry = array('id'=>$row['id'],
						'cell'=>array(
								'id'       => $row['id'],
								'lang'     => $_lang,
								'title'    => dejsonByLang($row['title'],$lang),
								'module_name'      => $row['module_name'],
								'module_tag'     => $row['module_tag'],
								'module_pid'    => $module_pid,
								'module_type'   => L('mod_form_ele_module_type'.$row['module_type']),
								'addtime'  => date('Y-m-d',$row['addtime']),
								'deal' => $deal
						),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
		}else{
			$lang_filter = C('LANG_ARRAY');
			$this->assign("lang_filter",$lang_filter);
			
			$this->display();
		}
	}
	
	//添加
	public function add(){
		
		$module  = D("Module");
		$langs   = C("LANG_ARRAY");
		
		if(IS_POST){
			
			if($module->create()){			
				foreach($langs as $k=>$v){
					$row[$k] = $this->_post('title_'.$k,'','');
				}
				$module->title = json_encode($row);				
				$id = $module->add();
				
				$_module_name = strtolower($this->_param("module_name","trim","desc"));
				$_lang = getLang();
				$_title = $this->_param("title_".$_lang,"trim","desc");
				$_table = C('DB_PREFIX').$_module_name;
				
				//创建模型数据表
				$create_sql = "CREATE TABLE IF NOT EXISTS `".$_table."` (
								`id` int(11) NOT NULL AUTO_INCREMENT,
								`solevar` char(32) NOT NULL,
								`cateid` int(11) DEFAULT '0',
								`lang` varchar(10) NOT NULL,
								`cmodule` varchar(40) DEFAULT '' COMMENT '内容所属模型',
								`for_site` int(11) DEFAULT '0' COMMENT '信息属于哪个站点',
								`for_front` varchar(40) DEFAULT NULL COMMENT '信息属于哪个前端',
								`keywrods` varchar(30) DEFAULT NULL COMMENT '关键字',
								`description` varchar(255) DEFAULT NULL COMMENT '描述',
								`addtime` int(11) DEFAULT '0' COMMENT '添加时间',
								`addid` int(11) DEFAULT '0' COMMENT '添加用户Id',
								`isdel` tinyint(1) NOT NULL DEFAULT '2' COMMENT '删除标志位(1删除2:未删除)',
								PRIMARY KEY (`id`)
								) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='".$_title."';
							";
				$module->query($create_sql);
				$module->cacheModule($id);
				
				wlog(1);
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->success(L('cfg_form_tipmsg_addsucc'));
			} else { 
				wlog(2,$module->getError());
				$this->error($module->getError());
			}
		} else {
			$lang    = create_option_key(C("LANG_ARRAY"),getLang());
			$this->assign("lang",$lang);
			$this->assign('langs',$langs);
			$this->display();
		}
	}
	
	//修改
	public function edit(){
		$module = D("Module");
		$langs  = C("LANG_ARRAY");
		$id 	= $this->_param('id','intval',0);
		$where  = "id=$id";
		
		if(IS_POST){
			if($module->create()){			
				foreach($langs as $k=>$v){
					$row[$k] = $this->_post('title_'.$k,'','');
				}
				$module->title = json_encode($row);				
				$module->where($where)->save();
				
				$_module_name = strtolower($this->_param("module_name","trim",""));
				$_module_name_old = strtolower($this->_param("module_name_old","trim",""));
				$_lang = getLang();
				$_title = $this->_param("title_".$_lang,"trim","desc");
				$_table = C('DB_PREFIX').$_module_name;
				$_old_table = C('DB_PREFIX').$_module_name_old;
				
				$_lang = getLang();
				$_title = $this->_param("title_".$_lang,"trim","desc");
				
				if($_module_name_old != $_module_name && trim($_module_name)){
					//创建模型数据表
					$rename_sql = "RENAME TABLE `".$_old_table."` TO `".$_table."`;ALTER TABLE `".$_table."` COMMENT='".$_title."';";
					$module->query($rename_sql);
					//exit($module->getlastSql());
				}
				$module->cacheModule($id);
				wlog(1);
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->success(L('cfg_form_tipmsg_editsucc'));
			} else {
				wlog(2,$module->getError());
				$this->error($module->getError());
			}
		} else {
			$id        = $this->_param('id','intval',0);
			if(!$id) $this->error(L('cfg_form_tipmsg_illgel'));
			
			$edit_data = $module->find($id); 
			$this->assign("edit_data",$edit_data);
			
			//语言
			$lang    = create_option_key(C("LANG_ARRAY"),$edit_data['lang']);
			
			//模型名称
			$title   = json_decode($edit_data['title'],true);
			$title_arr = array();
			foreach($langs as $k=>$v){
				if(isset($title[$k])){
					$title_arr[] =array("k"=>$k,"v"=>$v,"lang"=>$title[$k]);
				}else{
					$title_arr[] =array("k"=>$k,"v"=>$v,"lang"=>'');
				}
			}
			
			$this->assign("title_arr",$title_arr);
			$this->assign("lang",$lang);
			$this->assign("edit_data",$edit_data);
			$this->assign('langs',$langs);
			$this->display();
		}
	}
	
	//模型继承
	public function inherit(){
		
		$module = D("Module");
		$langs  = C("LANG_ARRAY");
		$nowLang = getLang();
		$id 	= $this->_param('id','intval',0);
		$where  = "id=$id";

		if(IS_POST){
			if($module->create()){
				//处理模型标题
				foreach($langs as $k=>$v){
					$row[$k] = $this->_post('title_'.$k,'','');
				}
				$module->title = json_encode($row);	
				
				//处理模型继承字段
				if(is_array($module->filed_inherit)){
					$module->filed_inherit = implode(',',$module->filed_inherit);
				}
							
				$nowid = $module->add();
				$module->cacheModule($nowid);
				
				$_module_name = strtolower($this->_param("module_name","trim","desc"));
				$_lang = getLang();
				$_title = $this->_param("title_".$_lang,"trim","desc");
				$_table = C('DB_PREFIX').$_module_name;
				
				//创建模型数据表
				$create_sql = "CREATE TABLE IF NOT EXISTS `".$_table."` (
								`id` int(11) NOT NULL AUTO_INCREMENT,
								`solevar` char(32) NOT NULL,
								`cateid` int(11) DEFAULT '0',
								`lang` varchar(10) NOT NULL,
								`cmodule` varchar(40) DEFAULT '' COMMENT '内容所属模型',
								`for_site` int(11) DEFAULT '0' COMMENT '信息属于哪个站点',
								`for_front` varchar(40) DEFAULT NULL COMMENT '信息属于哪个前端',
								`keywrods` varchar(30) DEFAULT NULL COMMENT '关键字',
								`description` varchar(255) DEFAULT NULL COMMENT '描述',
								`addtime` int(11) DEFAULT '0' COMMENT '添加时间',
								`addid` int(11) DEFAULT '0' COMMENT '添加用户Id',
								`isdel` tinyint(1) NOT NULL DEFAULT '2' COMMENT '删除标志位(1删除2:未删除)',
								PRIMARY KEY (`id`)
								) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='".$_title."';
							";
				$module->query($create_sql);
				//exit($module->getlastSql());
				
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->success(L('cfg_form_tipmsg_addsucc'));
			} else { 
				$this->error($module->getError());
			}
		} else {
			$id        = $this->_param('id','intval',0);
			if(!$id) $this->error(L('cfg_form_tipmsg_illgel'));
			
			$edit_data = $module->find($id); 
			$this->assign("edit_data",$edit_data);
			
			//父模型字段列表
			$Module_field = M('Module_filed');
			$data_field = $Module_field->where('module_id='.$id)->select();
			
			$filed_inherit = '';
			foreach($data_field as $v){				
				$filed_title = dejsonByLang($v['filed_title'],$nowLang);
				$filed_inherit .= '<span><input type="checkbox" name="filed_inherit[]" checked value="'.$v['id'].'"> '.$filed_title.'</option></span>';
			}
			
			//语言
			$lang = create_option_key(C("LANG_ARRAY"),$edit_data['lang']);
			
			$this->assign("title_arr",$title_arr);
			$this->assign("lang",$lang);
			$this->assign("filed_inherit",$filed_inherit);
			$this->assign("edit_data",$edit_data);
			$this->assign('langs',$langs);
			$this->display();
		}
	}
	
	//列表属性设置
	public function listedit(){
		$id  = $this->_param('id','intval',0);
		$Module = M('Module');
		$langs  = C("LANG_ARRAY");
		
		if(IS_POST){
			$edit_data = $_POST['edit_data'];
			/*print_r($edit_data);
			exit();*/
			$list_attr = $edit_data['list_attr'];
			foreach($list_attr['colModel']['name'] as $k=>$v){
				$Module_field = M('Module_filed');
				$data_field = $Module_field->where('id='.$v)->find();
				$list_attr['colModel']['name'][$k] = $data_field['filed_name'];
				$list_attr['colModel']['nameid'][$k] = $v;
			}
			$Module->list_attr = json_encode($list_attr);
			$Module->where('id='.$id)->save();
			
			$this->assign("jumpUrl",U('/Module/index'));   
			$this->success(L('cfg_form_tipmsg_editsucc'));
		}else{
			$edit_data = $Module->find($id);
			$edit_data['list_attr'] = json_decode($edit_data['list_attr'],true);
			/*print_r($data['list_attr']);
			exit();*/
			$lang = getLang();
			$module_title = dejsonByLang($edit_data['title'],$lang);
			
			//查询字段
			if($edit_data['module_type']==2){
				$wid = $edit_data['module_pid'].','.$id;
				$where = "module_id IN ($wid)";
			}else{
				$where = "module_id=$id";
			}
			
			$Module_field = M('Module_filed');
			$data_field = $Module_field->where($where)->select();
			$module_filed = '';
			foreach($data_field as $v){
				$filed_title[$v['id']] = json_decode($v['filed_title'],true);
			}
			$filed_title = json_encode($filed_title);
			
			//字段列表
			$table_addColumn = '';
			foreach($edit_data['list_attr']['colModel']['name'] as $k=>$v){
				$table_addColumn .= '<table cellpadding="2" cellspacing="1" width="600" class="table_addColumn">';
				$table_addColumn .= '<tr><td class="th" width="80"><a class="btn red icn-only delColumn"><i class="icon-remove icon-white"></i></a></td><td></td></tr>';
				$table_addColumn .= '<tr><td class="th" width="80">字段名称</td><td><select class="span6 m-wrap filedName" name="edit_data[list_attr][colModel][name][]"><option value="none">'.L('cfg_form_tis_select').'</option>';
				
				foreach($data_field as $dv){
					if($edit_data['list_attr']['colModel']['nameid'][$k]==$dv['id']){
						$table_addColumn .= '<option value="'.$dv['id'].'" selected="selected">'.$dv['filed_name'].'</option>';
					}else{
						$table_addColumn .= '<option value="'.$dv['id'].'">'.$dv['filed_name'].'</option>';
					}
				}
				
				$table_addColumn .= '</select></td></tr>';
				$table_addColumn .= '<tr><td class="th">显示名称</td><td>';
				foreach($langs as $lk=>$lv){
					$table_addColumn .= $lv.':<input type="text" name="edit_data[list_attr][colModel][display]['.$lk.'][]" data-required="1" style="width:80px;" class="filed_display" lang="'.$lk.'" value="'.$edit_data['list_attr']['colModel']['display'][$lk][$k].'"/>&nbsp;&nbsp;&nbsp;';
				}  
				$table_addColumn .= '</td></tr>';
				$table_addColumn .= '<tr><td class="th">是否排序</td><td><label class="radio"><input type="checkbox" value="1" name="edit_data[list_attr][colModel][ordertable][]"';
				if($edit_data['list_attr']['have_search']==1){
					$table_addColumn .= "checked='checked'";
				}
				$table_addColumn .= '>'.L('cfg_form_tis_yes').'</label><label class="radio"><input type="checkbox" value="2" name="edit_data[list_attr][colModel][ordertable][]"';
				if($edit_data['list_attr']['have_search']==2){
					echo "checked='checked'";
				}
				$table_addColumn .= '>'.L('cfg_form_tis_no').'</label></td></tr>';
				$table_addColumn .= '<tr><td class="th">样式名称</td><td> <input type="text" class="input-text" size="50"  name="edit_data[list_attr][colModel][myclass][]" value="'.$edit_data['list_attr']['colModel']['myclass'][$k].'" /></td></tr></table>';
			}
			
			if($table_addColumn==''){
				$table_addColumn .= '<table cellpadding="2" cellspacing="1" width="600" class="table_addColumn">';
				$table_addColumn .= '<tr><td class="th" width="80"><a class="btn red icn-only delColumn"><i class="icon-remove icon-white"></i></a></td><td></td></tr>';
				$table_addColumn .= '<tr><td class="th" width="80">字段名称</td><td><select class="span6 m-wrap filedName" name="edit_data[list_attr][colModel][name][]"><option value="none">'.L('cfg_form_tis_select').'</option>';
				
				foreach($data_field as $dv){
					$table_addColumn .= '<option value="'.$dv['id'].'">'.$dv['filed_name'].'</option>';
				}
				
				$table_addColumn .= '</select></td></tr>';
				$table_addColumn .= '<tr><td class="th">显示名称</td><td>';
				foreach($langs as $lk=>$lv){
					$table_addColumn .= $lv.':<input type="text" name="edit_data[list_attr][colModel][display]['.$lk.'][]" data-required="1" style="width:80px;" class="filed_display" lang="'.$lk.'" value=""/>&nbsp;&nbsp;&nbsp;';
				}  
				$table_addColumn .= '</td></tr>';
				$table_addColumn .= '<tr><td class="th">是否排序</td><td><label class="radio"><input type="checkbox" value="1" name="edit_data[list_attr][colModel][ordertable][]">'.L('cfg_form_tis_yes').'</label><label class="radio"><input type="checkbox" value="2" name="edit_data[list_attr][colModel][ordertable][]">'.L('cfg_form_tis_no').'</label></td></tr>';
				$table_addColumn .= '<tr><td class="th">样式名称</td><td> <input type="text" class="input-text" size="50"  name="edit_data[list_attr][colModel][myclass][]" value="" /></td></tr></table>';
			}
			
			
			$this->assign('module_filed',$module_filed);
			$this->assign('module_title',$module_title);
			$this->assign('filed_title',$filed_title);
			$this->assign('edit_data',$edit_data);
			$this->assign('table_addColumn',$table_addColumn);
			$this->assign('id',$id);
			$this->assign('langs',$langs);
			$this->display();
		}
	}
	
	//删除
	public function del(){
		$id = $this->_get('id');
		$Module = M('Module');
		$data  = $Module->find($id);
		
		//删除模型对应表
		$_module_name = strtolower($data['module_name']);
		$_table = C('DB_PREFIX').$_module_name;
		$delete_sql = 'DROP TABLE `'.$_table.'`;';
		$Module->query($delete_sql);
		
		//清空模型Tab类别
		$Module_tab = M('Module_tab');
		$where = "module_id=$id";
		$res = $Module_tab->where($where)->delete();
		
		//清空模型字段记录
		$Module_filed = M('Module_filed');
		$where = "module_id=$id";
		$res = $Module_filed->where($where)->delete();
		
		$res = $Module->delete($id);
				
		if($res) {
			wlog(1);
			$Module->cacheModule($id);
			$this->success(L('cfg_form_tipmsg_delsucc'));
		} else {
			wlog(2);
			$this->error(L('cfg_form_tipmsg_delfail'));
		}
	}
	
	//ajax
	public function listjson(){
		import('ORG.Util.Page');
		$Module  = D("Module");

		$orderDesc = $this->_get("orderDirection","trim","desc");
		$orderName = $this->_get("orderName","trim","addtime");
		$pageNum   = $this->_get("pageNum","intval",C('web_admin_pagenum'));
		
		$map       = unescape($this->_get("where"));
		$map       = "1=1 ".$map;
		$count     = $Module->where($map)->count();
		$Page      = new Page($count);
        $nowPage   = isset($_GET['p'])?$_GET['p']:1;
        $show      = $Page->show();
        $list      = $Module->where($map)->order($orderName.' '.$orderDesc)
		                  ->page($nowPage.','.$pageNum)->select();
		$totalPage = ceil($count/$pageNum);
		C('web_admin_pagenum',$pageNum);
		
		$jsonData  = array('page'=>$nowPage,'total'=>$count,'rows'=>array(),'totalPage'=>$totalPage);
		$lang    = getLang();
		foreach($list AS $row){
			if(array_key_exists($row['lang'],C('LANG_ARRAY'))){
				$_lang = $row['lang'];
			}else{
				$_lang = L('cfg_form_tis_select_nolang');
			}
			
			//父模型名称
			if($row['module_pid']){
				$pModule = M('Module');
				$pData  = $pModule->find($row['module_pid']);
				$module_pid = $pData['module_name'];
			}else{
				$module_pid = L('mod_inherit_form_ele_nopid');
			}
			
			
			//处理字符串
			$deal = '';
			$deal .= '<a href="'.__URL__.'/tablist/id/'.$row['id'].'" class="btn blue icn-only" title="'.L('mod_list_deal_tab').'"><i class="icon-list"></i></a>';
			$deal .= '<a href="'.__URL__.'/filedlist/id/'.$row['id'].'" class="btn green icn-only" title="'.L('mod_list_deal_filed').'"><i class=" icon-columns"></i></a>';
			$deal .= '<a href="'.__URL__.'/edit/id/'.$row['id'].'" class="btn purple icn-only" title="'.L('cfg_list_itf_btn_modify').'" data-id="'.$row['id'].'"><i class="icon-edit"></i></a>';
			$deal .= '<a href="'.__URL__.'/listedit/id/'.$row['id'].'" class="btn yellow icn-only" title="'.L('mod_list_btn_listset').'" data-id="'.$row['id'].'"><i class="icon-cog"></i></a>';
			if($row['module_type']==1){
				$deal .= '<a href="'.__URL__.'/inherit/id/'.$row['id'].'" class="btn icn-only" title="'.L('mod_listedit_form_btn_copy').'" data-id="'.$row['id'].'"><i class="icon-copy"></i></a>';
			}
			
			$deal .= '<a href="'.__APP__.'/'.ucfirst($row['module_name']).'/" class="btn black icn-only" title="'.L('mod_listedit_form_btn_see').'"><i class="icon-hand-right"></i></a>';
			$deal .= '<a class="btn red icn-only delAlone" title="'.L('cfg_list_itf_btn_delete').'" data-id="'.$row['id'].'"><i class="icon-remove"></i></a>';
			
			$entry = array('id'=>$row['id'],
				'cell'=>array(
					'id'       => $row['id'],
					'lang'     => $_lang,
					'title'    => dejsonByLang($row['title'],$lang),
					'module_name'      => $row['module_name'],
					'is_open'     => $row['is_open']==1?L('cfg_form_tis_yes'):L('cfg_form_tis_no'),
					'is_system'     => $row['is_system']==1?L('cfg_form_tis_yes'):L('cfg_form_tis_no'),
					'module_pid'    => $module_pid,
					'module_type'   => $row['module_type']==1?L('mod_inherit_form_ele_type_1'):L('mod_inherit_form_ele_type_2'),
					'addtime'  => date('Y-m-d',$row['addtime']),
					'deal' => $deal
				),
			);
			$jsonData['rows'][] = $entry;
		}
		$this->ajaxReturn($jsonData,'JSON');
	}
	
	/***************************模型类别开始****************************/
	//Tab列表
	public function tablist(){
		$id  = $this->_get('id','intval',0);
		
		$Module = M('Module');		
		$data  = $Module->find($id);
		$lang    = getLang();
		$module_title = dejsonByLang($data['title'],$lang);
		

		if($data['module_type']==2){
			$wid = $data['module_pid'].','.$id;
			$where = "module_id IN ($wid)";
		}else{
			$where = "module_id=$id";
		}
		
		$Module_tab  = M("Module_tab");
		$list = $Module_tab->where($where)->order('order_num DESC')->select();
		
		$html = '';
		foreach($list as $v){
			$deal = '';
			if($v['module_id']==$id){
				$deal .= '<a href="'.__URL__.'/tabedit/id/'.$v['id'].'" class="btn blue icn-only" title="'.L('cfg_list_itf_btn_modify').'"><i class="icon-edit"></i></a>';
				$deal .= ' <a href="'.__URL__.'/tabdel/id/'.$v['id'].'" class="btn red icn-only" title="'.L('cfg_list_itf_btn_delete').'"><i class="icon-remove"></i></a>';
			}else{
				$deal .= '<a class="btn blue icn-only disabled" title="'.L('cfg_list_itf_btn_modify').'"><i class="icon-edit"></i></a>';
				$deal .= ' <a class="btn red icn-only disabled" title="'.L('cfg_list_itf_btn_delete').'"><i class="icon-remove"></i></a>';
			}
			
			$html .= '<tr>';
			$html .= '<td><input type="text" name="order_num['.$v['id'].']" size="3" value="'.$v['order_num'].'" style="width:55px"></td>';
			$html .= '<td>'.dejsonByLang($v['tab_name'],$lang).'</td>';
			$html .= '<td class="center">'.$deal.'</td>';
			$html .= '</tr>';
		}
		
		$this->assign("module_id",$id);
		$this->assign('module_title',$module_title);
		$this->assign('html_tree',$html);
		$this->display();
	}
	
	//添加
	public function tabadd(){
		$module_id = $this->_param('module_id','intval',0);
		$langs  = C("LANG_ARRAY");
		$Module_tab  =  D("Module_tab");
		
		if(IS_POST){
			if($Module_tab->create()){			
				foreach($langs as $k=>$v){
					$row[$k] = $this->_post('tab_name_'.$k,'','');
				}
				$Module_tab->tab_name = json_encode($row);				
				$Module_tab->add();
				
				$this->assign("jumpUrl",U('/Module/tablist/id/'.$module_id));   
				$this->success(L('cfg_form_tipmsg_addsucc'));
			} else {
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->error($Module_tab->getError());
			}
		} else {
			$Module = M('Module');
			//$where = "id=$id";
			$data  = $Module->find($module_id);
			$lang    = getLang();
			$module_title = dejsonByLang($data['title'],$lang);
			
			$tab_type_list = '';
			foreach(C('TAB_TYPE') as $k=>$v){
				$tab_type_list .= '<option value="'.$k.'">'.L($v).'</option>';
			}
			
			$this->assign('tab_type_list',$tab_type_list);
			$this->assign('langs',$langs);
			$this->assign('module_title',$module_title);
			$this->assign("module_id",$module_id);
			$this->display();
		}
	}
	
	//修改
	public function tabedit(){
		$id = $this->_param('id','intval',0);
		$where = "id=$id";
		$langs  = C("LANG_ARRAY");
		$Module_tab  =  D("Module_tab");
		
		if(IS_POST){
			if($Module_tab->create()){					
				foreach($langs as $k=>$v){
					$row[$k] = $this->_post('tab_name_'.$k,'','');
				}
				$Module_tab->tab_name = json_encode($row);				
				
				$Module_tab->where($where)->save();
				
				$module_id = $this->_param('module_id','intval',0);
				$this->assign("jumpUrl",U('/Module/tablist/id/'.$module_id));   
				$this->success(L('cfg_form_tipmsg_addsucc'));
			} else {
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->error($Module_tab->getError());
			}
		} else {
			$Module_tab = D("Module_tab");
			$edit_data = $Module_tab->find($id);
			
			$module_id = $edit_data['module_id'];
			$Module = M('Module');
			$data  = $Module->find($module_id);
			$lang    = getLang();
			$module_title = dejsonByLang($data['title'],$lang);
			
			//模型类别
			$tab_name   = json_decode($edit_data['tab_name'],true);
			$tab_name_arr = array();
			foreach($langs as $k=>$v){
				if(isset($tab_name[$k])){
					$tab_name_arr[] =array("k"=>$k,"v"=>$v,"lang"=>$tab_name[$k]);
				}else{
					$tab_name_arr[] =array("k"=>$k,"v"=>$v,"lang"=>'');
				}
			}
			
			$tab_type_list = '';
			foreach(C('TAB_TYPE') as $k=>$v){
				if($edit_data['tab_type']==$k){
					$tab_type_list .= '<option value="'.$k.'" selected>'.L($v).'</option>';
				}else{
					$tab_type_list .= '<option value="'.$k.'">'.L($v).'</option>';
				}
			}
			
			$this->assign('tab_type_list',$tab_type_list);
			$this->assign("tab_name_arr",$tab_name_arr);
			$this->assign('module_title',$module_title);
			$this->assign("module_id",$module_id);
			$this->assign("edit_data",$edit_data);
			$this->display();
		}
	}
	
	//删除
	public function tabdel(){
		$id = $this->_get('id');
		$Module_tab = M('Module_tab');
		
		//判断是否模型字段中关联了Tab
		$Module_filed = M('Module_filed');
		if($Module_filed->where('tab_id='.$id)->find()){
			$this->assign("jumpUrl",U('/Module/tablist/id/'.$id));
			$this->error(L('mod_tab_list_del_notempty_tis'));
			exit();
		}
		
		$data = $Module_tab->find($id);
		$module_id = $data['module_id'];
		
		$res = $Module_tab->where("id=$id")->delete();
		
		if($res) {
			$this->assign("jumpUrl",U('/Module/tablist/id/'.$module_id));
			$this->success(L('cfg_form_tipmsg_delsucc'));
		} else {
			$this->assign("jumpUrl",U('/Module/tablist/id/'.$module_id));
			$this->error(L('cfg_form_tipmsg_delfail'));
		}
	}
	
	//类别排序
	public function tabsort(){
		$order_nums = $this->_POST('order_num');
		$module_id = $this->_POST('module_id');
		
		if(!is_array($order_nums))$this->error(L('cfg_form_tipmsg_illgel'));
		
		foreach ($order_nums as $id => $num) {
			M('Module_tab')->save( array('id' =>$id , 'order_num' =>intval($num) ) );
		}
		
		$this->assign("jumpUrl",U('/Module/tablist/id/'.$module_id));
		$this->success(L('mod_tab_list_sort_tis'));
	}
	/***************************模型类别结束****************************/
	
	/***************************模型字段开始****************************/
	public function filedlist(){
		$id  = $this->_get('id','intval',0);
		
		$Module = M('Module');		
		$data  = $Module->find($id);
		$lang    = getLang();
		$langs  = C("LANG_ARRAY");
		$module_title = dejsonByLang($data['title'],$lang);
		
		if($data['module_type']==2){
			$wid = $data['module_pid'].','.$id;
			$where = "module_id IN ($wid)";
		}else{
			$where = "module_id=$id";
		}
		
		$Module_filed  = D("Module_filed");
		$list = $Module_filed->where($where)->order('order_num DESC')->select();
		
		$html = '';
		foreach($list as $v){
			//获取类别Id
			if($v['tab_id']){
				$Module_tab  = M("Module_tab");
				$data_tab = $Module_tab->find($v['tab_id']);
				$tab_name = dejsonByLang($data_tab['tab_name'],$lang);
			}else{
				$tab_name = L('mod_list_no_tab_name');
			}
			$status = $v['status']==1?L('cfg_form_tis_yes'):L('cfg_form_tis_no');
			$is_system = $v['is_system']==1?L('cfg_form_tis_yes'):L('cfg_form_tis_no');
			
			$deal = '';
			if($v['module_id']==$id){
				$deal .= '<a href="'.__URL__.'/filededit/id/'.$v['id'].'" class="btn blue icn-only" title="'.L('cfg_list_itf_btn_modify').'"><i class="icon-edit"></i></a>';
				$deal .= ' <a href="'.__URL__.'/fileddel/id/'.$v['id'].'" class="btn red icn-only" title="'.L('cfg_list_itf_btn_delete').'"><i class="icon-remove"></i></a>';
			}else{
				$deal .= '<a class="btn blue icn-only disabled" title="'.L('cfg_list_itf_btn_modify').'"><i class="icon-edit"></i></a>';
				$deal .= ' <a class="btn red icn-only disabled" title="'.L('cfg_list_itf_btn_delete').'"><i class="icon-remove"></i></a>';
			}
			
			$html .= '<tr>';
			$html .= '<td><input type="text" name="order_num['.$v['id'].']" size="3" value="'.$v['order_num'].'" style="width:55px"></td>';
			$html .= '<td>'.$module_title.'</td>';
			$html .= '<td>'.$tab_name.'</td>';
			$html .= '<td>'.dejsonByLang($v['filed_title'],$lang).'</td>';
			$html .= '<td>'.$v['filed_name'].'</td>';
			$html .= '<td>'.$status.'</td>';
			$html .= '<td>'.$is_system.'</td>';
			$html .= '<td class="center">'.$deal.'</td>';
			$html .= '</tr>';
		}
		
		$this->assign("module_id",$id);
		$this->assign('module_title',$module_title);
		$this->assign('html_tree',$html);
		$this->display();
	}
	//添加
	public function filedadd(){
		$module_id = $this->_param('module_id','intval',0);
		$langs  = C("LANG_ARRAY");
		$Module_filed  =  D("Module_filed");
		$lang    = getLang();
		$Module  = D('Module');

		
		if(IS_POST){
			if($Module_filed->create()){
				//字段显示
				$filed_show = $_POST['filed_show'];
				
				//字段名称		
				foreach($langs as $k=>$v){
					$row_filed_title[$k] = $this->_post('filed_title_'.$k,'','');
				}
				
				//字段属性
				$filed_attr = $_POST['filed_attr'];
				
				//表单校验属性
				$valid_attr = $_POST['valid_attr'];
				$valids = array('default','success','required','minlength','maxlength','regex');
				foreach($valids as $valid){
					if(!$valid_attr['auto'][$valid.'_tis']){
						$valid_attr['auto'][$valid.'_tis'] = 'no';
						unset($var);
						foreach($langs as $k=>$v){
							$var[$k] = $valid_attr['tis'][$valid.'_'.$k];
							unset($valid_attr['tis'][$valid.'_'.$k]);
						}
						$valid_attr['tis'][$valid] = json_encode($var);
					}else{
						$valid_attr['auto'][$valid.'_tis'] = 'ok';
						$valid_attr['tis'][$valid] = '';
					}
				}
				
				$Module_filed->filed_title = json_encode($row_filed_title);
				$Module_filed->filed_attr = json_encode($filed_attr);
				$Module_filed->valid_attr = json_encode($valid_attr);

				$Module_filed->add();
				
				if($filed_show!='3'){
					//在模型数据表中新增字段
					$Module_data  = $Module->find($module_id);
					$module_name = $Module_data['module_name'];
					
					$filed_name = $this->_post('filed_name','trim','');
					$fieldtype = $this->_post('filed_type','trim','');
					
					$attr['type'] = '';
					$attr['type_pram'] = '';
					$attr['default'] = $filed_attr['default'];
					$attr['comment'] = $row_filed_title[$lang];
					if($fieldtype=='text' || $fieldtype=='password' || $fieldtype=='textarea' || $fieldtype=='htmlarea' || $fieldtype=='float' || $fieldtype=='int' || $fieldtype=='date'){
						
						if($filed_name=='keywrods' || $filed_name=='description'){
							//keywrods、description是默认字段，无须改变表结构
						}else{
							$attr['type'] = $filed_attr['fieldtype'];
						}
						
						
						if($filed_attr['type_pram']){
							$attr['type_pram'] = $filed_attr['type_pram'];
						}
					}
					
					if($fieldtype=='radio' || $fieldtype=='checkbox' || $fieldtype=='select' || $fieldtype=='linkage'){
						$attr['type'] = 'int';
					}
					
					if($fieldtype=='lang'){
						//$attr['type'] = 'lang';
						$filed_attr['fieldtype'] = 'varchar';
						$filed_attr['type_pram'] = '10';
					}
					
					if($fieldtype=='cate'){
						//$attr['type'] = 'cate';
						$filed_attr['fieldtype'] = 'int';
					}
					
					if($attr['type']){
						$_table = C('DB_PREFIX').$module_name;
						$create_sql = $this->_createColumnSql($filed_name,'add',$attr);
			
						$Module_filed->query('ALTER TABLE '.$_table.' '.$create_sql);
					}
				}
				$Module->cacheModuleField($module_id);
				$this->assign("jumpUrl",U('/Module/filedlist/id/'.$module_id));   
				$this->success(L('cfg_form_tipmsg_addsucc'));
			} else {
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->error($Module_filed->getError());
			}
		} else {
			
			$data  = $Module->find($module_id);
			$module_title = dejsonByLang($data['title'],$lang);
			
			//字段类型
			$filed_type = '';
			foreach(C('FILED_TYPE') as $k=>$v){
				$filed_type .= '<option value="'.$k.'">'.L($v).'</option>';
			}
			
			//查询模型信息
			$Module = M('Module');
			$data   = $Module->find($module_id);
			$name   = $data['module_name'];
			$pid    = $data['module_pid'];
			
			//模块类别
			$Module_tab = M('Module_tab');
			$module_tab_list = '';
			$Module_arr = $Module_tab->where('module_id IN ('.$module_id.','.$pid.')')->order('order_num DESC')->select();
			foreach($Module_arr as $k=>$v){
				$module_tab_list .= '<option value="'.$v['id'].'">'.dejsonByLang($v['tab_name'],$lang).'</option>';
			}	
			
			$this->assign('langs',$langs);
			$this->assign('module_title',$module_title);
			$this->assign("module_id",$module_id);
			$this->assign("filed_type",$filed_type);
			$this->assign("module_tab_list",$module_tab_list);
			$this->display();
		}
	}
	
	//修改
	public function filededit(){
		$id = $this->_param('id','intval',0);
		$module_id = $this->_param('module_id','intval',0);
		$where = "id=$id";
		$langs = C("LANG_ARRAY");
		$Module_filed  =  D("Module_filed");
		$lang = getLang();
		$Module = D('Module');
		
		if(IS_POST){
			if($Module_filed->create()){
				//字段显示
				$filed_show = $_POST['filed_show'];
				
				//字段名称
				foreach($langs as $k=>$v){
					$row_filed_title[$k] = $this->_post('filed_title_'.$k,'','');
				}
				
				//字段属性
				$filed_attr = $_POST['filed_attr'];
				
				//表单校验属性
				$valid_attr = $_POST['valid_attr'];
				$valids = array('default','success','required','minlength','maxlength','regex');
				foreach($valids as $valid){
					if(!$valid_attr['auto'][$valid.'_tis']){
						$valid_attr['auto'][$valid.'_tis'] = 'no';
						unset($var);
						foreach($langs as $k=>$v){
							$var[$k] = $valid_attr['tis'][$valid.'_'.$k];
							unset($valid_attr['tis'][$valid.'_'.$k]);
						}
						$valid_attr['tis'][$valid] = json_encode($var);
					}
				}
				
				$Module_filed->filed_title = json_encode($row_filed_title);
				$Module_filed->filed_attr = json_encode($filed_attr);
				$Module_filed->valid_attr = json_encode($valid_attr);

				$Module_filed->where($where)->save();
				
				if($filed_show!='3'){
					//在模型数据表中修改字段
					$Module_data  = $Module->find($module_id);
					$module_name = $Module_data['module_name'];
						
					$filed_name = $this->_post('filed_name','trim','');
					$fieldtype  = $this->_post('filed_type','trim','');
					$attr['type'] = '';
					$attr['type_pram'] = '';
					$attr['default'] = $filed_attr['default'];
					$attr['comment'] = $row_filed_title[$lang];
					if($fieldtype=='text' && $fieldtype=='password' && $fieldtype=='textarea' && $fieldtype=='htmlarea' && $fieldtype=='float' && $fieldtype=='radio' && $fieldtype=='checkbox' && $fieldtype=='select' && $fieldtype=='int' && $fieldtype=='date'){
						if($filed_name=='keywrods' || $filed_name=='description'){
							//keywrods、description是默认字段，无须改变表结构
						}else{
							$attr['type'] = $filed_attr['fieldtype'];
						}
						if($filed_attr['type_pram']){
							$attr['type_pram'] = $filed_attr['type_pram'];
						}
					}
					
					if($fieldtype=='lang'){
						//$attr['type'] = 'lang';
						$filed_attr['fieldtype'] = 'varchar';
						$filed_attr['type_pram'] = '10';
					}
					
					if($fieldtype=='cate'){
						//$attr['type'] = 'cate';
						$filed_attr['fieldtype'] = 'int';
					}
					
					if($attr['type']){
						$_table = C('DB_PREFIX').$module_name;
						$create_sql = $this->_createColumnSql($filed_name,'change',$attr);
						$Module_filed->query('ALTER TABLE '.$_table.' '.$create_sql);
					}
				}
				$Module->cacheModuleField($module_id);
				$this->assign("jumpUrl",U('/Module/filedlist/id/'.$module_id));   
				$this->success(L('cfg_form_tipmsg_editsucc'));
			} else {
				$this->assign("jumpUrl",U('/Module/index'));   
				$this->error($Module_filed->getError());
			}
		} else {
			$edit_data = $Module_filed->find($id);
			$module_id = $edit_data['module_id'];
			
			$data  = $Module->find($module_id);
			$module_title = dejsonByLang($data['title'],$lang);
			
			//字段类型
			$filed_type = '';
			foreach(C('FILED_TYPE') as $k=>$v){
				if($edit_data['filed_type']==$k){
					$filed_type .= '<option value="'.$k.'" selected="selected">'.L($v).'</option>';
				}else{
					$filed_type .= '<option value="'.$k.'">'.L($v).'</option>';
				}
			}
			
			//查询模型信息
			$data   = $Module->find($module_id);
			$name   = $data['module_name'];
			$pid    = $data['module_pid'];
			
			//模块类别
			$Module_tab = M('Module_tab');
			$module_tab_list = '';
			$Module_arr = $Module_tab->where('module_id IN ('.$module_id.','.$pid.')')->order('order_num DESC')->select();
			
			foreach($Module_arr as $k=>$v){
				if($edit_data['tab_id']==$v['id']){
					$module_tab_list .= '<option value="'.$v['id'].'" selected>'.dejsonByLang($v['tab_name'],$lang).'</option>';
				}else{
					$module_tab_list .= '<option value="'.$v['id'].'">'.dejsonByLang($v['tab_name'],$lang).'</option>';
				}
			}
			
			//字段名称
			$filed_title   = json_decode($edit_data['filed_title'],true);
			$filed_title_arr = array();
			foreach($langs as $k=>$v){
				if(isset($filed_title[$k])){
					$filed_title_arr[] =array("k"=>$k,"v"=>$v,"lang"=>$filed_title[$k]);
				}else{
					$filed_title_arr[] =array("k"=>$k,"v"=>$v,"lang"=>'');
				}
			}
			
			//表单校验属性
			$valid_attr   = json_decode($edit_data['valid_attr'],true);
			$valid_attr_arr   = json_decode($edit_data['valid_attr'],true);
						
			foreach($valid_attr_arr['tis'] as $vk=>$vv){
				foreach($langs as $k=>$v){
					$var = json_decode($vv,true);					
					foreach($langs as $k=>$v){
						$valid_attr['tis'][$vk.'_'.$k] = $var[$k];						
					}
					unset($valid_attr['tis'][$vk]);
				}
			}
			
			$this->assign('langs',$langs);
			$this->assign('module_title',$module_title);
			$this->assign("module_id",$module_id);
			$this->assign("id",$id);
			$this->assign("filed_type",$filed_type);
			$this->assign("module_tab_list",$module_tab_list);
			$this->assign("edit_data",$edit_data);
			$this->assign("valid_attr",$valid_attr);
			$this->assign('filed_title_arr',$filed_title_arr);
			$this->display();
		}
	}
	
	//删除
	public function fileddel(){
		$id = $this->_get('id');
		$Module_filed = M('Module_filed');
		$Module  = D('Module');
	
		
		$data = $Module_filed->find($id);
		$module_id = $data['module_id'];
		$filed_name = $data['filed_name'];
		
		$res = $Module_filed->where("id=$id")->delete();
		
		if($filed_name=='keywrods'||$filed_name=='description'||$filed_name=='lang'||$filed_name=='cateid'){
			//系统默认字段无须删除结构
		}else{
			if($filed_name){
				$Module_data  = $Module->find($module_id);
				$module_name = $Module_data['module_name'];
				
				$_table = C('DB_PREFIX').$module_name;
				$Module_filed->query('ALTER TABLE '.$_table.' DROP COLUMN `'.$filed_name.'`;');
			}
		}
		
		if($res) {
			$Module->cacheModuleField($module_id);
			$this->assign("jumpUrl",U('/Module/filedlist/id/'.$module_id));
			$this->success(L('cfg_form_tipmsg_delsucc'));
		} else {
			$this->assign("jumpUrl",U('/Module/filedlist/id/'.$module_id));
			$this->error(L('cfg_form_tipmsg_delfail'));
		}
	}
	
	//获取字段类型模板
	function filedtype(){
		$lang = getLang();
		$type = $this->_param('type','trim','');
		$id = $this->_param('id','intval',0);
		if($id){
			$Module_filed  =  D("Module_filed");
			$edit_data = $Module_filed->find($id);
			$filed_attr   = json_decode($edit_data['filed_attr'],true);
		}else{
			$filed_attr = '';
		}
		
		
		if($type=='radio' || $type=='checkbox' || $type == 'select' || $type == 'linkage' ){
			$Model_dict = D("Dict");
			$map_dict['pid']   = 0 ;
			$map_dict['level'] = 1 ;
			
			if($type == 'linkage' ){
				$map_dict['type'] = 2 ;
			}else{
				$map_dict['type'] = 1 ;
			}
			
			$list_dict = $Model_dict->where($map_dict)->select();
			$dict_str = '';
			foreach($list_dict as $k=>$v){
				$title = json_decode($v['value'],true);
				
				if($filed_attr['options']==$v['id']){
					$dict_str .= '<option value="'.$v['id'].'" selected>'.$title[$lang].'</option>';
				}else{
					$dict_str .= '<option value="'.$v['id'].'">'.$title[$lang].'</option>';
				}
			}
			
			$this->assign("dict_str",$dict_str);
		}
				
		$this->assign("filed_attr",$filed_attr);
		$this->assign("type",$type);
		$this->display();
	}
	
	/**
	 * 生成模型缓存
	 */
	public function cache(){
	
		$model = D("Module");
		$model->cacheModule();
		wlog(1);
		$this->success("生成模型缓存成功");
	}
	
	//字段排序
	public function filedsort(){
		$order_nums = $this->_POST('order_num');
		$module_id = $this->_POST('module_id');
		
		if(!is_array($order_nums))$this->error(L('cfg_form_tipmsg_illgel'));
		
		foreach ($order_nums as $id => $num) {
			M('Module_filed')->save( array('id' =>$id , 'order_num' =>intval($num) ) );
		}
		$Module  = D('Module');
		$Module->cacheModuleField($module_id);
		
		$this->assign("jumpUrl",U('/Module/filedlist/id/'.$module_id));
		$this->success(L('mod_tab_list_sort_tis'));
	}
	/***************************模型字段结束****************************/
	
	/***************************私有方法开始****************************/
	private function _createColumnSql($filed_name,$event,$attr){
		$sql = '';
		if($event=='add'){
			$sql .= 'ADD COLUMN ';
		}else{
			$sql .= 'CHANGE COLUMN ';
		}
		$sql .= ' `'.$filed_name.'` ';
		
		if($attr['type']=='char'){
			if($attr['type_pram']){
				$sql .= ' char('.$attr['type_pram'].') ';
			}else{
				$sql .= ' char(255) ';
			}
		}elseif($attr['type']=='varchar'){
			if($attr['type_pram']){
				$sql .= ' varchar('.$attr['type_pram'].') ';
			}else{
				$sql .= ' varchar(255) ';
			}
		}elseif($attr['type']=='text'){
			$sql .= ' text ';
		}elseif($attr['type']=='mediumtext'){
			$sql .= ' mediumtext ';
		}elseif($attr['type']=='tinyint'){
			$sql .= ' tinyint(3) ';
		}elseif($attr['type']=='smallint'){
			$sql .= ' smallint(6) ';
		}elseif($attr['type']=='mediumint'){
			$sql .= ' mediumint(9) ';
		}elseif($attr['type']=='int'){
			$sql .= ' int(11) ';
		}elseif($attr['type']=='bigint'){
			$sql .= ' bigint(20) ';
		}elseif($attr['type']=='float'){
			$sql .= ' float('.$attr['type_pram'].') ';
		}elseif($attr['type']=='double'){
			$sql .= ' double('.$attr['type_pram'].') ';
		}elseif($attr['type']=='date'){
			$sql .= ' date ';
		}elseif($attr['type']=='timestamp'){
			$sql .= ' timestamp ';
		}elseif($attr['type']=='datetime'){
			$sql .= ' datetime ';
		}
		
		$sql .= ' NULL ';
		if($attr['type']=='timestamp'){
			$sql .= ' DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ';
		}else{
			if($attr['default']){
				$sql .= ' DEFAULT \''.$attr['default'].'\' ';
			}
		}
		
		if($attr['comment']){
			$sql .= ' COMMENT \''.$attr['comment'].'\' ';
		}
		$sql .= ';';
		
		return $sql;
	}
	/***************************私有方法结束****************************/
}

//清除分类缓存
function clean_module_cache(){
	$data  =  D("Module");
	F('module',NULL);
	$data->getAllModule();
}
?>